package com.rabbiter.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {

    private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);

    // 定义一个切点，匹配Controller层的方法
    @Pointcut("execution(* com.rabbiter.controller..*.*(..))")
    public void controllerMethods() {
        // 切点定义，无方法体
    }

    @AfterReturning(pointcut = "controllerMethods()", returning = "result")
    public void logAfterControllerMethodReturning(JoinPoint joinPoint, Object result) {
        logger.info("{} method executed successfully in Controller. Result: {}", joinPoint.getSignature().getName(), result);
    }

}